﻿namespace Patterns.Tools.CodeGenerators.GoogleCode
{
	public abstract class WikiModel
	{
		private string _baseWikiUri;
		private string _baseSourceUri;

		public string SourceUri { get; protected set; }
		public string Summary { get; protected set; }
		public virtual string WikiName { get; set; }
		public virtual string Target { get; set; }
		public virtual string TargetType { get; set; }
		public virtual string Sidebar{ get; set; }

		public virtual string BaseWikiUri
		{
			get { return _baseWikiUri; }
			set
			{
				if (value.StartsWith(_baseWikiUri)) return;
				_baseWikiUri = value.Trim('/');
			}
		}

		public virtual string BaseSourceUri
		{
			get { return _baseSourceUri; }
			set
			{
				if (value.StartsWith(_baseSourceUri)) return;
				_baseSourceUri = value.Trim('/');
			}
		}

		public virtual string WikiUri
		{
			get { return string.Format("{0}/{1}", BaseWikiUri, WikiName); }
		}

		public virtual string GetWikiUri(string relativeUri)
		{
			return GetFullUri(_baseWikiUri, relativeUri);
		}

		public virtual string GetSourceUri(string relativeUri)
		{
			return GetFullUri(_baseSourceUri, relativeUri);
		}

		private static string GetFullUri(string baseUri, string relativeUri)
		{
			return string.Format("{0}/{1}", baseUri, relativeUri.Trim('/'));
		}

		public virtual void Initialize()
		{
			
		}
	}
}